package org.ali.structuralpattern.compositepattern.node;

import org.ali.structuralpattern.compositepattern.component.Component2;

import java.util.ArrayList;

/**
 * 树枝节点
 */
public class Branch2 implements Component2 {
    private final ArrayList<Component2> children = new ArrayList<>();
    private final String name;

    public Branch2(String name) {
        this.name = name;
    }

    /**
     * 增加子节点
     */
    public void add(Component2 component) {
        children.add(component);
    }

    @Override
    public void showMessage() {
        System.out.println(name + "树枝节点：");
        for (Component2 component : children) {
            component.showMessage();
        }
    }
}
